package edu.scut.course_management.dao;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;

import edu.scut.course_management.dto.SHBriefInfoDTO;
import edu.scut.course_management.dto.SHBriefInfoPreDTO;
import edu.scut.course_management.po.Answer;

/**
 * 数据访问 对应库表：answer
 * 
 * @author huaming
 */
@Repository
public interface AnswerMapper {
    
    // 创建新的answer 采用回填技术
    void addAnswer(List<Answer> answers) throws DataAccessException;
    // 通过作业查出所有学生的完成情况 因为要有学生的姓名 有级联查询
    List<SHBriefInfoPreDTO> findAnswerByHomeworkId(Integer homeworkId);
    // 通过homeworkId和studentId来查询Answer记录
    Answer findAnswerByHomeworkIdAndStudentId(@Param("homeworkId")Integer homeworkId, @Param("studentId")String studentId);
    // 通过homeworkId和studentId来找到对应记得记录 并更新answerContent
    void updataAnswerContentByhomeworkIdAndStudentId(@Param("homeworkId")Integer homeworkId, 
        @Param("studentId")String studentId, @Param("answerContent")String answerContent) throws DataAccessException;

    // 通过homeworkId和studentId来找到对应记录 并返回answerId
    Integer findAnswerIdByHomeworkIdAndStudentId(@Param("homeworkId")Integer homeworkId, @Param("studentId")String studentId);
    
    // 通过homeworkId和studentId来找到记录 并更新teacherReply和score
    void updateTAndScoreByHomeworkIdAndStudentId(@Param("homeworkId")Integer homeworkId, @Param("studentId")String studentId,
         @Param("score")Integer score) throws DataAccessException;
}
